#include <iostream>
#include "../taskPool.hpp"

using namespace std;
using uint = unsigned int;


class testTask : public EvenTask
{
    public:
    testTask(uint num) : data(num){}

    public:
    virtual bool task() 
    {
        cout << data << " -- -- " <<this_thread::get_id() << endl;
        if(data%10 == 0 && (data < 10000))
        {
            for(uint i = 1; i <= 10; i++)
            {
                shared_ptr<EvenTask> t = make_shared<testTask>(data+i);
                TASKPOOL::getInstance()->commitTask(t);
            }
        }
        //this_thread::sleep_for(std::chrono::milliseconds(10));
    }

    private:
    uint data = 0;
};



class test
{
    public:
    void start()
    {

        for(uint i = 0; i < 10000; i += 10)
        {
            shared_ptr<EvenTask> t = make_shared<testTask>(i);
            TASKPOOL::getInstance()->commitTask(t);
        }
    }

};





#include <unistd.h>
int main()
{
    TASKPOOL::getInstance();

    test a;
    a.start();

#if 1

    while(TASKPOOL::getInstance()->isBusy())
    {
        cout <<"busy" << endl;
        this_thread::sleep_for(std::chrono::seconds(2));
    }
#endif
 this_thread::sleep_for(std::chrono::seconds(2));


 a.start();


 #if 1

    while(TASKPOOL::getInstance()->isBusy())
    {
        cout <<"busy" << endl;
        this_thread::sleep_for(std::chrono::seconds(2));
    }
#endif
 this_thread::sleep_for(std::chrono::seconds(1));


cout <<"endllllll" << endl;
    //sleep(10);
    return 0;
}